<html>
<head><meta charset="utf-8"><title>Getting the names of trait parameters · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20names.20of.20trait.20parameters.html">Getting the names of trait parameters</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="236591975"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Getting%20the%20names%20of%20trait%20parameters/near/236591975" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Xavier Denis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20names.20of.20trait.20parameters.html#236591975">(Apr 28 2021 at 22:46)</a>:</h4>
<p>Is there a query which provides me with the names of the parameters of a trait? By that I mean that given</p>
<div class="codehilite"><pre><span></span><code>trait T&lt;A, B&gt; { .. }
</code></pre></div>
<p>return <code>[A, B]</code></p>



<a name="236592839"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Getting%20the%20names%20of%20trait%20parameters/near/236592839" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Xavier Denis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20names.20of.20trait.20parameters.html#236592839">(Apr 28 2021 at 22:55)</a>:</h4>
<p>hmm it seems like <code>TraitRef::identity()</code> does what I want, but is that a guarantee?</p>



<a name="236681233"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Getting%20the%20names%20of%20trait%20parameters/near/236681233" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20names.20of.20trait.20parameters.html#236681233">(Apr 29 2021 at 14:23)</a>:</h4>
<p><span class="user-mention" data-user-id="312719">@Xavier Denis</span> The best way would be to use <code>tcx.generics_of</code></p>



<a name="236681324"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Getting%20the%20names%20of%20trait%20parameters/near/236681324" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20names.20of.20trait.20parameters.html#236681324">(Apr 29 2021 at 14:24)</a>:</h4>
<p>you can then iterate over <code>Generics.params</code></p>



<a name="236681481"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Getting%20the%20names%20of%20trait%20parameters/near/236681481" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Xavier Denis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Getting.20the.20names.20of.20trait.20parameters.html#236681481">(Apr 29 2021 at 14:25)</a>:</h4>
<p>oh that's <em>much</em> nicer</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>